#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int cmpint(const void *p1, const void *p2)
{
    return *((int *)p1) - *((int *)p2);
}

int main()
{
    size_t n = 0;
    while (scanf("%d", &n) != EOF)
    {
        int *pn1 = NULL;
        pn1 = (int *)malloc(sizeof(int) * n);
        int *pn2 = NULL;
        pn2 = (int *)malloc(sizeof(int) * 1000);
        for (int i = 0; i < n; i++)
        {
            scanf("%d", pn1 + i);
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                int flag1 = 0;
                if (*(pn1 + i) % *(pn1 + j) == 0 && *(pn1 + i) != *(pn1 + j))
                {
                    goto laber;
                }
            }
        }
        int q = 0;
        for (int k = 0; k < n; k++)
        {
            for (int j = 1; j < *(pn1 + k); j++)
            {
                int flag2 = 1;
                if (*(pn1 + k) % j == 0)
                {
                    for (int p = 2; p < j; p++)
                    {
                        if (j % p == 0)
                        {
                            flag2 = 0;
                            break;
                        }
                    }
                    if (flag2 == 1)
                    {
                        *(pn2 + q) = j;
                        q++;
                    }
                }
            }
        }
        qsort(pn2, q, sizeof(pn2[0]), cmpint);
        int count = 0;
        for (int i = 0; i < q; i++)
        {
            if (pn2[i] == pn2[i + 1] || pn2[i] == 1)
            {
                pn2[i] = 0;
                count++;
            }
        }
        int sum = 0;
        for (int j = 0; j < 4 + count; j++)
        {
            sum = sum + pn2[j];
        }
        printf("%d", sum);
        free(pn1);
        free(pn2);
        continue;
    laber:
        printf("-1");
    }
    return 0;
}